# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
#	           ChangeSet	1.1063.1.17 -> 1.1063.1.18
#	include/asm-ppc64/pgtable.h	1.6     -> 1.7    
#	include/asm-ppc/pgtable.h	1.18    -> 1.19   
#	include/asm-x86_64/pgtable.h	1.5     -> 1.6    
#	  drivers/char/mem.c	1.22    -> 1.22.1.1
#	include/asm-i386/pgtable.h	1.8     -> 1.9    
#	include/asm-m68k/pgtable.h	1.3     -> 1.4    
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.20
# [TG3]: Fix AC1001 typo in pci_ids.h
# --------------------------------------------
# 03/08/25	m.c.p@wolk-project.de	1.1063.17.1
# [PATCH] Handle get_block errors correctly in block_read_full_page()
# 
# Hi Marcelo,
# 
# quoting Andrea:
# 
# > Anton found get_block errors weren't handled correctly by
# > block_read_full_page(). This is my proposed fix for the problem,
# > implementation and patching is from Anton Altaparmakov.
# 
# It's in -aa and -wolk for some time.
# 
# Please apply for 2.4.23-pre1. Thank you :)
# --------------------------------------------
# 03/08/25	marcelo@logos.cnet	1.1063.17.2
# Merge http://jfs.bkbits.net/linux-2.4
# into logos.cnet:/home/marcelo/bk/linux-2.4
# --------------------------------------------
# 03/08/25	m.c.p@wolk-project.de	1.1063.17.3
# [PATCH] LVM Update v1.0.5 to v1.0.7
# 
# On Thursday 31 July 2003 03:04, Marcelo Tosatti wrote:
# 
# Hi Marcelo,
# 
# > > would you consider updating LVM from 1.05 to 1.07 in -pre10? It's out
# > > there for many months now, many vendor tree's are using it, my tree uses
# > > it and prolly many others and I am not aware of any problems.
# > > Should I send a patch? Please let me know.
# > It depends on the type of changes. I prefer including it in -pre10 only if
# > its obvioux bugfixes only.
# > Please send me it together with a detailed changelog.
# 
# ok, here we go, 5 small but important bugfixes:
# 
# Changes from v1.0.5 -> v1.0.7
# -----------------------------
# o fixed lvrename bug leaving wrong filesystem entries around in /proc/lvm/
# o fixed lvextend/lvreduce bug on snapshots preventing correct reload of the
#   excpetion table possibly giving wrong snapshot content.
# o fixed snapshot extend/reduce memory leak
# o fixed wrong VG PE counter
# o some whitespace cleanup
# --------------------------------------------
# 03/08/25	jgarzik@redhat.com	1.1063.12.21
# [NET]: Backport ethtool_ops from 2.6.x
# --------------------------------------------
# 03/08/25	m.c.p@wolk-project.de	1.1063.17.4
# [PATCH] CONFIG_NR_CPUS
# 
# Hi Marcelo,
# 
# this patch has been around for ages. 2.6 has the same change/cleanup.
# 
# Now, w/o the patch, the kernel will be compiled with 32 CPUs, allthough you
# might only have 2 or 4 or so.
# 
# This is purely to save memory - each supported CPU adds approximately eight
# kilobytes to the kernel image.
# --------------------------------------------
# 03/08/25	jgarzik@redhat.com	1.1063.2.6
# [ia32] mention that X86_VENDOR_ID is tied to NCAPINTS,
# in a comment in arch/i386/kernel/head.S.
# --------------------------------------------
# 03/08/25	jgarzik@redhat.com	1.1063.2.7
# Merge redhat.com:/garz/repo/marcelo-2.4
# into redhat.com:/garz/repo/hwrandom-2.4
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.22
# [NET]: Include asm/uaccess.h in net/core/ethtool.c
# --------------------------------------------
# 03/08/25	marcelo@logos.cnet	1.1063.17.5
# Cset exclude: m.c.p@wolk-project.de|ChangeSet|20030825194257|34486
# --------------------------------------------
# 03/08/25	m.c.p@wolk-project.de	1.1063.17.6
# [PATCH] Avoid potentially leaking pagetables into the per-cpu queues
# 
# Hi Marcelo,
# 
# $subject says it all.
# 
# Patch from Andrea Arcangeli!
# 
# It's in -aa since 2.4.17rc2aa1, in -wolk for some time.
# --------------------------------------------
# 03/08/25	m.c.p@wolk-project.de	1.1063.17.7
# [PATCH] Proper APIC with HyperThreading
# 
# Hi Marcelo,
# 
# the boot issue with DL760 G2 issue with Hyper-Threading (16-way
# logical) was root-caused to be coming from hardcoding of apic-version
# during the acpi boot-up code. The attached patch fixes the issue, by
# reading in the actual apic version. This apic-version is used later in
# the boot process, to identify whether the processor supports xAPIC or
# not. And that in turn was resulting in boot failure.
# 
# Refer following lkml threads for detailed the problem description:
# Subject: SUMMARY: DL760 G2 issue with Hyper-Threading:
# Subject: PROBLEM: DL760 G2 issue on 2.4.21 with Hyper-Threading
# 
# In -ac and -wolk for some time.
# 
# Patch by "Venkatesh Pallipadi"
# --------------------------------------------
# 03/08/25	jgarzik@redhat.com	1.1063.2.8
# Merge redhat.com:/garz/repo/marcelo-2.4
# into redhat.com:/garz/repo/hwrandom-2.4
# --------------------------------------------
# 03/08/25	mikpe@csd.uu.se	1.1063.17.8
# [PATCH] 2.4.22 local APIC updates 1/3: remove incorrect blacklist rules
# 
# Marcelo,
# 
# This patch removes the x86 local APIC blacklist rules for the
# Microstar 6163 and Intel AL440LX mainboards, as these boards
# _do_ work with local APIC enabled.
# 
# The AL440LX blacklist rule was the only place where the
# dont_enable_local_apic_timer flag could be set, so the patch
# removes that variable and the code which checks it.
# 
# The hangs these boards used to have has since been traced to
# a combination of using specific graphics cards with APM's
# DISPLAY_BLANK option.
# 
# Backport from 2.5.72. Also tested in 2.4 for months. Please apply.
# 
# /Mikael
# --------------------------------------------
# 03/08/25	mikpe@csd.uu.se	1.1063.17.9
# [PATCH] 2.4.22 local APIC updates 2/3: add lapic/nolapic options
# 
# Marcelo,
# 
# This patch adds the lapic and nolapic kernel options, which give
# users greater control of the local APIC enable process on x86:
# - "nolapic" prevents the kernel from enabling or using the local
#   APIC. This is stronger than listing a machine in the DMI scan
#   blacklist, since it also works for machines that boot with the
#   local APIC already enabled.
#   "nolapic" can also be seen as a simple-to-deploy alternative to
#   keeping the DMI blacklist rules up-to-date.
# - "lapic" tells the kernel to force-enable the P4 local APIC if
#   the BIOS disabled it. This is needed on some machines. The
#   default (don't enable if BIOS didn't) can't be changed since
#   there is an even larger number of P4s where ACPI breaks if the
#   local APIC is enabled.
# 
# Backport from 2.6.0-test4. Tested in 2.4.22-rc. Please apply.
# 
# This patch renames the dont_enable_local_apic variable, so if you
# apply it you also need to apply "local APIC updates 1/3: remove
# incorrect blacklist rules".
# 
# /Mikael
# --------------------------------------------
# 03/08/25	mikpe@csd.uu.se	1.1063.17.10
# [PATCH] 2.4.22 local APIC updates 3/3: disable APIC_BASE on reboot
# 
# Marcelo,
# 
# This patch ensures that we properly disable the local APIC before
# reboot. This fixes BIOS problems reported by a few people.
# 
# disable_local_APIC() now checks if detect_init_APIC() enabled the
# local APIC via the APIC_BASE MSR, and if so it now disables APIC_BASE.
# Previously we would leave APIC_BASE enabled, and that made some
# BIOSen malfunction.
# 
# The SMP reboot code calls disable_local_APIC(). On SMP HW there is
# no change since detect_init_APIC() isn't called and APIC_BASE isn't
# enabled by us. An SMP kernel on UP HW behaves just like an UP_APIC
# kernel, so it disables APIC_BASE if we enabled it at boot.
# 
# The UP_APIC suspend code is simplified since the existing code to
# disable APIC_BASE is moved into disable_local_APIC().
# 
# (Felix Kühling originally reported the BIOS reboot problem. This is
# a fixed-up version of his preliminary patch.)
# 
# Backport from 2.6.0-test4. Tested in 2.4.22-rc. Please apply.
# 
# /Mikael
# --------------------------------------------
# 03/08/25	marcelo@logos.cnet	1.1063.16.2
# Merge bk://kernel.bkbits.net/davem/sparc-2.4
# into logos.cnet:/home/marcelo/bk/linux-2.4
# --------------------------------------------
# 03/08/25	jgarzik@redhat.com	1.1063.18.1
# Merge redhat.com:/garz/repo/marcelo-2.4
# into redhat.com:/garz/repo/net-drivers-2.4
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.23
# Merge nuts.ninka.net:/home/davem/src/BK/sparc-2.4
# into nuts.ninka.net:/home/davem/src/BK/tg3-2.4
# --------------------------------------------
# 03/08/25	jmorris@intercode.com.au	1.1063.12.24
# [TG3]: skb_headlen() cleanup.
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.25
# [TG3]: Update to irqreturn_t.
# --------------------------------------------
# 03/08/25	jgarzik@redhat.com	1.1063.12.26
# [TG3]: Detect shared (and screaming) interrupts.
# --------------------------------------------
# 03/08/25	greg@kroah.com	1.1063.12.27
# [TG3]: pci_device_id can not be marked __devinitdata.
# --------------------------------------------
# 03/08/25	jgarzik@redhat.com	1.1063.12.28
# [TG3]: Convert to using ethtool_ops.
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.29
# [TG3]: Sync TSO changes from base 2.5.x
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.30
# [TG3]: Merge comment typo fixes from 2.5.x
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.31
# [TG3]: Initial implementation of 5705 support.
# --------------------------------------------
# 03/08/25	jgarzik@redhat.com	1.1063.12.32
# [TG3]: Bug fixes for 5705 support.
# 
# - (major) status block DMA address wasn't being set, for 5705. whoops. :)
# - (minor) pass 5705-specific RX_STD_MAX_SIZE
# - (minor) don't program RCVBDI_JUMBO_THRESH reg on 5705
# - (very minor) re-order *THRESH, HOSTCC* regs per bcm570x driver order
# --------------------------------------------
# 03/08/25	jgarzik@redhat.com	1.1063.12.33
# [TG3]: More 5705 updates.
# 
# - do not zero stats/status block on 5705, they don't exist
#   (in controller memory, at least)
# - define TG3_MAX_MTU macro such that it takes a (tp) pointer arg,
#   because the value varies between 5705 and non-5705
# - use the macro to simply tg3_change_mtu
# --------------------------------------------
# 03/08/25	jgarzik@redhat.com	1.1063.12.34
# [TG3]: More 5705 fixes.
# 
# - call set-wire-speed phy function from tg3_phy_reset, not just _phy_probe
# - disable set-wire-speed usage on certain chips, per bcm5700 driver
# --------------------------------------------
# 03/08/25	marcelo@logos.cnet	1.1063.2.9
# Merge bk://kernel.bkbits.net/jgarzik/hwrandom-2.4
# into logos.cnet:/home/marcelo/bk/linux-2.4
# --------------------------------------------
# 03/08/25	jgarzik@redhat.com	1.1063.12.35
# [TG3]: Another 5705 fix: enable eeprom write prot as needed.
# --------------------------------------------
# 03/08/25	jgarzik@redhat.com	1.1063.12.36
# [TG3]: Only write the on-nic sram addr on non-5705.
# --------------------------------------------
# 03/08/25	jgarzik@redhat.com	1.1063.12.37
# [TG3]: Add 5782 pci id.
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.38
# [TG3]: Fix statistics on 5705.
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.39
# [TG3]: Do not reset the RX_MAC unless PHY is Serdes.
# 
# Bug discovered by Michael Chan @ Broadcom.
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.40
# [TG3]: More missing PCI IDs.
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.41
# [TG3]: Reset PHY more reliably on 570{3,4,5} chips.
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.42
# [TG3]: Fix 5788/5901, update TSO code.
# - Do not set RDMAC_MODE_FIFO_LONG_BURST on 5788
# - Do not set WDMAC_MODE_RX_ACCEL on 5788
# - Note that 5788 cannot use tagged irq status.
# - 5788 cannot do TSO
# - 5788 cannot do NETIF_F_HIGHDMA.
# - 5901 is 10/100 only.
# - Update TSO firmware, add 5705 specific TSO firmware.
# - Update TSO packet handling in ->hard_start_xmit() to
#   match updated TSO firmware.
# - TSO is still off by default until more perf analysis is done.
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.43
# [TG3]: Differentiate between TSO capable and TSO enabled.
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.44
# [TG3]: Add {get,set}_tso ethtool_ops support.
# 
# Also, include TSO support code when NETIF_F_TSO is available
# but do not enable TSO by default even on capable cards.  User
# can turn it on via ethtool.
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.45
# [TG3]: Bump version/reldate.
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.46
# [TG3]: Fix tg3_phy_reset_5703_4_5 chip rev test.
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.47
# [TG3]: Bump version/reldate.
# --------------------------------------------
# 03/08/25	davem@nuts.ninka.net	1.1063.12.48
# [TG3]: More fixes and enhancements.
# 
# - Use ethtool_op_{get,set}_tso().
# - Avoid partial byte enables on DMA writes, this upsets several
#   non-x86 PCI controllers.
# --------------------------------------------
# 03/08/25	marcelo@logos.cnet	1.1063.2.10
# Merge bk://kernel.bkbits.net/jgarzik/net-drivers-2.4
# into logos.cnet:/home/marcelo/bk/linux-2.4
# --------------------------------------------
# 03/08/26	ak@muc.de	1.1063.2.11
# [PATCH] Compile fix for ACPI in 2.4.22/x86-64
# 
# Marcelo unfortunately added an last minute ACPI update that changed
# ACPI interfaces and broke x86-64 compilation. I didn't catch it in
# time, so 2.4.22 does not compile out of the box for AMD64.
# 
# This patch fixes it.
# You'll have to apply it when compiling 2.4.22 for x86-64
# 
# -Andi
# --------------------------------------------
# 03/08/26	arjanv@redhat.com	1.1063.2.12
# [PATCH] Fix asm constraint bug in arch/i386/kernel/pci-pc.c
# 
# Hi,
# 
# Reported by HP, found by Jakub.
# The patch below fixes a missing asm constraint. The asm constraint of this
# function needs to depend on (opt) so that gcc knows that the
# initialisation of the opt structure needs to happen before the asm code;
# in the old code only the address of opt was in the constraints which isn't
# enough. Newer gcc will just miscompile this for p4.
# 
# Greetings,
#     Arjan van de Ven
# --------------------------------------------
# 03/08/26	marcelo@logos.cnet	1.1063.2.13
# Merge bk://kernel.bkbits.net/davem/net-2.4
# into logos.cnet:/home/marcelo/bk/linux-2.4
# --------------------------------------------
# 03/08/26	hch@lst.de	1.1063.2.14
# [PATCH] use list_add_tail in buffer_insert_list
# 
# This is a really old patch from the XFS tree.
# 
# We need to call list_add_tail in buffer_insert_list to preserve buffer
# ordering.  This essential for a good extent layout with XFS's delayed
# allocation and a while ago the reiserfs group requested the same change.
# 
# ACKed by sct.
# --------------------------------------------
# 03/08/26	willy@w.ods.org	1.1063.2.15
# [PATCH] make log buffer length selectable
# 
# On Mon, Aug 25, 2003 at 04:48:30AM -0700, Marcelo Tosatti wrote:
# > final:
# >
# > - 2.4.22-rc4 was released as 2.4.22 with no changes.
# 
# Hi Marcelo,
# 
# as you requested, here is the log_buf_len patch for inclusion in 23-pre.
# 
# Cheers,
# Willy
# --------------------------------------------
# 03/08/26	johnstul@us.ibm.com	1.1063.2.16
# [PATCH] Do not clear SMI pin at bootup
# 
# Marcelo, All,
# 
#       Some of our more recent hardware requires that SMIs are routed
# through the IOAPIC, thus when we clear_IO_APIC() at boot time, we clear
# the BIOS initialized SMI pin (which is unfortunately not described in
# the MPS or ACPI tables). This basically clobbers the SMI, which can
# cause problems with console redirection as well keeping us from being
# able to transition into full ACPI mode.
# 
# This patch (back ported from 2.5) simply reads the apic entry in
# clear_IO_APIC to make sure the delivery_mode isn't dest_SMI. If it is,
# we leave the apic entry alone and return.
# 
# With this patch, booting with full ACPI works and SMIs function
# properly.
# 
# Please consider for acceptance.
# 
# thanks
# -john
# --------------------------------------------
# 03/08/26	willy@debian.org	1.1063.19.1
# [netdrvr 3c59x] ethtool_ops support
# --------------------------------------------
# 03/08/26	bjorn.helgaas@hp.com	1.1069.1.21
# ia64: initialize bootmem early for acpi_table_init().
# --------------------------------------------
# 03/08/26	hch@lst.de	1.1063.2.17
# [PATCH] reserve a sysctl number for XFS (pagebuf)
# 
# Reserve the 2.5 number for VM_PAGEBUF in 2.4 aswell.
# --------------------------------------------
# 03/08/26	jgarzik@redhat.com	1.1063.19.2
# [netdrvr sis900] ethtool_ops support
# --------------------------------------------
# 03/08/26	jgarzik@redhat.com	1.1063.19.3
# [netdrvr sis900] minor bits from 2.6
# --------------------------------------------
# 03/08/26	jgarzik@redhat.com	1.1063.19.4
# [netdrvr 8139cp] minor bits from 2.6
# --------------------------------------------
# 03/08/26	stelian@popies.net	1.1063.2.18
# [PATCH] sonypi driver update
# 
# Hi,
# 
# Now that we are starting a new -pre cycle, here are the latest
# sonypi updates:
# 	* document the fact that FX501/FX702 laptops are not supported
# 
# 	* add battery insert/remove events (thanks to Daniel K.)
# 
# 	* improve the event detection using a different port offset
# 	  on 'type2' models (thanks to Daniel K.)
# 
# 	* now that ACPI is finally in the kernel, simplify the ACPI
# 	  tests.
# 
# Marcelo, please apply.
# 
# Stelian.
# 
# ===== Documentation/sonypi.txt 1.12 vs edited =====
# --------------------------------------------
# 03/08/26	stelian@popies.net	1.1063.2.19
# [PATCH] meye driver updates
# 
# The attached patch updates the meye driver with some tiny changes:
# 	* use SetPageReserved instead of mem_map_reserve, and remove
# 	  the wrapper.h dependency
# 	* document the supported hardware.
# 
# ===== Documentation/video4linux/meye.txt 1.6 vs edited =====
# --------------------------------------------
# 03/08/26	johnstul@us.ibm.com	1.1063.2.20
# [PATCH] Handle clustered XAPIC in set_ioapic_affinity()
# 
# Marcelo, All,
# 
# 	In set_ioapic_affinity() we take a cpu mask which we normally pass into
# the apic. However, on xapics in clustered physical mode (ie: x440s) we
# need to convert this mask into a physical apicid before sending it to
# the apic. If clustered_apic_mode is XAPIC, this patch selects the lowest
# cpu in the mask and routes the interrupts there. This avoids
# timedoubling and other interrupt misdirection seen on x440s after
# playing with /proc/irq/x/smp_affinity.
# 
# Please apply.
# 
# thanks
# -john
# --------------------------------------------
# 03/08/26	jgarzik@redhat.com	1.1063.19.5
# [netdrvr 8139cp] ethtool_ops support
# --------------------------------------------
# 03/08/26	jgarzik@redhat.com	1.1063.19.6
# [netdrvr 3c59x] add a piece missed in previous ethtool_ops patch
# 
# Contributed by Matthew Wilcox.
# --------------------------------------------
# 03/08/26	jgarzik@redhat.com	1.1063.19.7
# [netdrvr 3c501] ethtool_ops support
# --------------------------------------------
# 03/08/26	akpm@digeo.com	1.1063.1.18
# [PATCH] drivers/char/mem.c cleanup
# 
# From: David Mosberger <davidm@napali.hpl.hp.com>
# 
# Here is a simplified version of the earlier /dev/mem cleanup.  This version
# of the patch no longer pretends to support uncached accesses via
# read()/write().  Instead, all it does is:
# 
# - consolidate much of the ugly code in uncached_access()
# 
# - move pgprot_noncached() macro to pgtable.h for i386, m68k, ppc, ppc64,
#   and x86_64
# 
# - fix the ia64 implementation to use efi_mem_attributes() to determine
#   the cacheability of an address
# 
# Eventually, we may want to replace the #ifdef CONFIG_IA64 with #ifdef
# CONFIG_EFI, but we can do this "on demand", if and when EFI-based x86
# machines become more common.
# 
# (Backported to 2.4 by Bjorn Helgaas).
# --------------------------------------------
#
diff -Nru a/drivers/char/mem.c b/drivers/char/mem.c
--- a/drivers/char/mem.c	Wed Oct  8 09:05:37 2003
+++ b/drivers/char/mem.c	Wed Oct  8 09:05:37 2003
@@ -26,6 +26,10 @@
 #include <asm/io.h>
 #include <asm/pgalloc.h>
 
+#ifdef CONFIG_IA64
+# include <linux/efi.h>
+#endif
+
 #ifdef CONFIG_I2C
 extern int i2c_init_all(void);
 #endif
@@ -41,7 +45,46 @@
 #if defined(CONFIG_S390_TAPE) && defined(CONFIG_S390_TAPE_CHAR)
 extern void tapechar_init(void);
 #endif
-     
+
+/*
+ * Architectures vary in how they handle caching for addresses
+ * outside of main memory.
+ *
+ */
+static inline int uncached_access(struct file *file, unsigned long addr)
+{
+#if defined(__i386__)
+	/*
+	 * On the PPro and successors, the MTRRs are used to set
+	 * memory types for physical addresses outside main memory,
+	 * so blindly setting PCD or PWT on those pages is wrong.
+	 * For Pentiums and earlier, the surround logic should disable
+	 * caching for the high addresses through the KEN pin, but
+	 * we maintain the tradition of paranoia in this code.
+	 */
+	if (file->f_flags & O_SYNC)
+		return 1;
+ 	return !( test_bit(X86_FEATURE_MTRR, boot_cpu_data.x86_capability) ||
+		  test_bit(X86_FEATURE_K6_MTRR, boot_cpu_data.x86_capability) ||
+		  test_bit(X86_FEATURE_CYRIX_ARR, boot_cpu_data.x86_capability) ||
+		  test_bit(X86_FEATURE_CENTAUR_MCR, boot_cpu_data.x86_capability) )
+	  && addr >= __pa(high_memory);
+#elif defined(CONFIG_IA64)
+	/*
+	 * On ia64, we ignore O_SYNC because we cannot tolerate memory attribute aliases.
+	 */
+	return !(efi_mem_attributes(addr) & EFI_MEMORY_WB);
+#else
+	/*
+	 * Accessing memory above the top the kernel knows about or through a file pointer
+	 * that was marked O_SYNC will be done non-cached.
+	 */
+	if (file->f_flags & O_SYNC)
+		return 1;
+	return addr >= __pa(high_memory);
+#endif
+}
+
 static ssize_t do_write_mem(struct file * file, void *p, unsigned long realp,
 			    const char * buf, size_t count, loff_t *ppos)
 {
@@ -78,7 +121,7 @@
 	unsigned long p = *ppos;
 	unsigned long end_mem;
 	ssize_t read;
-	
+
 	end_mem = __pa(high_memory);
 	if (p >= end_mem)
 		return 0;
@@ -122,86 +165,16 @@
 	return do_write_mem(file, __va(p), p, buf, count, ppos);
 }
 
-#ifndef pgprot_noncached
-
-/*
- * This should probably be per-architecture in <asm/pgtable.h>
- */
-static inline pgprot_t pgprot_noncached(pgprot_t _prot)
-{
-	unsigned long prot = pgprot_val(_prot);
-
-#if defined(__i386__) || defined(__x86_64__)
-	/* On PPro and successors, PCD alone doesn't always mean 
-	    uncached because of interactions with the MTRRs. PCD | PWT
-	    means definitely uncached. */ 
-	if (boot_cpu_data.x86 > 3)
-		prot |= _PAGE_PCD | _PAGE_PWT;
-#elif defined(__powerpc__)
-	prot |= _PAGE_NO_CACHE | _PAGE_GUARDED;
-#elif defined(__mc68000__)
-#ifdef SUN3_PAGE_NOCACHE
-	if (MMU_IS_SUN3)
-		prot |= SUN3_PAGE_NOCACHE;
-	else
-#endif
-	if (MMU_IS_851 || MMU_IS_030)
-		prot |= _PAGE_NOCACHE030;
-	/* Use no-cache mode, serialized */
-	else if (MMU_IS_040 || MMU_IS_060)
-		prot = (prot & _CACHEMASK040) | _PAGE_NOCACHE_S;
-#endif
-
-	return __pgprot(prot);
-}
-
-#endif /* !pgprot_noncached */
-
-/*
- * Architectures vary in how they handle caching for addresses 
- * outside of main memory.
- */
-static inline int noncached_address(unsigned long addr)
-{
-#if defined(__i386__)
-	/* 
-	 * On the PPro and successors, the MTRRs are used to set
-	 * memory types for physical addresses outside main memory, 
-	 * so blindly setting PCD or PWT on those pages is wrong.
-	 * For Pentiums and earlier, the surround logic should disable 
-	 * caching for the high addresses through the KEN pin, but
-	 * we maintain the tradition of paranoia in this code.
-	 */
- 	return !( test_bit(X86_FEATURE_MTRR, &boot_cpu_data.x86_capability) ||
-		  test_bit(X86_FEATURE_K6_MTRR, &boot_cpu_data.x86_capability) ||
-		  test_bit(X86_FEATURE_CYRIX_ARR, &boot_cpu_data.x86_capability) ||
-		  test_bit(X86_FEATURE_CENTAUR_MCR, &boot_cpu_data.x86_capability) )
-	  && addr >= __pa(high_memory);
-#elif defined(__ia64__)
-	struct page *page;
-
-	page = virt_to_page(__va(addr));
-	return !VALID_PAGE(page) || PageReserved(page);
-#else
-	return addr >= __pa(high_memory);
-#endif
-}
-
 static int mmap_mem(struct file * file, struct vm_area_struct * vma)
 {
 	unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
+	int uncached;
 
-	/*
-	 * Accessing memory above the top the kernel knows about or
-	 * through a file pointer that was marked O_SYNC will be
-	 * done non-cached.
-	 */
-#ifdef __ia64__
-	if (noncached_address(offset))
-#else
-	if (noncached_address(offset) || (file->f_flags & O_SYNC))
-#endif
+	uncached = uncached_access(file, offset);
+#ifdef pgprot_noncached
+	if (uncached)
 		vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+#endif
 
 	/* Don't try to swap out physical pages.. */
 	vma->vm_flags |= VM_RESERVED;
@@ -209,7 +182,7 @@
 	/*
 	 * Don't dump addresses that are not real memory to a core file.
 	 */
-	if (offset >= __pa(high_memory) || (file->f_flags & O_SYNC))
+	if (uncached)
 		vma->vm_flags |= VM_IO;
 
 	if (remap_page_range(vma->vm_start, offset, vma->vm_end-vma->vm_start,
@@ -584,6 +557,7 @@
 {
 	unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
 	unsigned long size = vma->vm_end - vma->vm_start;
+	int uncached;
 
 	/*
 	 * If the user is not attempting to mmap a high memory address then
@@ -594,13 +568,11 @@
 	if ((offset + size) < (unsigned long) high_memory)
 		return mmap_mem(file, vma);
 
-	/*
-	 * Accessing memory above the top the kernel knows about or
-	 * through a file pointer that was marked O_SYNC will be
-	 * done non-cached.
-	 */
-	if (noncached_address(offset) || (file->f_flags & O_SYNC))
+	uncached = uncached_access(file, offset);
+#ifdef pgprot_noncached
+	if (uncached)
 		vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+#endif
 
 	/* Don't do anything here; "nopage" will fill the holes */
 	vma->vm_ops = &kmem_vm_ops;
@@ -611,7 +583,8 @@
 	/*
 	 * Don't dump addresses that are not real memory to a core file.
 	 */
-	vma->vm_flags |= VM_IO;
+	if (uncached)
+		vma->vm_flags |= VM_IO;
 
 	return 0;
 }
diff -Nru a/include/asm-i386/pgtable.h b/include/asm-i386/pgtable.h
--- a/include/asm-i386/pgtable.h	Wed Oct  8 09:05:37 2003
+++ b/include/asm-i386/pgtable.h	Wed Oct  8 09:05:37 2003
@@ -302,6 +302,13 @@
 static inline void ptep_mkdirty(pte_t *ptep)			{ set_bit(_PAGE_BIT_DIRTY, ptep); }
 
 /*
+ * Macro to mark a page protection value as "uncacheable".  On processors which do not support
+ * it, this is a no-op.
+ */
+#define pgprot_noncached(prot)	((boot_cpu_data.x86 > 3)					  \
+				 ? (__pgprot(pgprot_val(prot) | _PAGE_PCD | _PAGE_PWT)) : (prot))
+
+/*
  * Conversion functions: convert a page and protection to a page entry,
  * and a page entry and page directory to the page they refer to.
  */
diff -Nru a/include/asm-m68k/pgtable.h b/include/asm-m68k/pgtable.h
--- a/include/asm-m68k/pgtable.h	Wed Oct  8 09:05:37 2003
+++ b/include/asm-m68k/pgtable.h	Wed Oct  8 09:05:37 2003
@@ -180,6 +180,24 @@
 
 #ifndef __ASSEMBLY__
 #include <asm-generic/pgtable.h>
+
+/*
+ * Macro to mark a page protection value as "uncacheable".
+ */
+#ifdef SUN3_PAGE_NOCACHE
+# define __SUN3_PAGE_NOCACHE	SUN3_PAGE_NOCACHE
+#else
+# define __SUN3_PAGE_NOCACHE	0
+#endif
+#define pgprot_noncached(prot)							\
+	(MMU_IS_SUN3								\
+	 ? (__pgprot(pgprot_val(prot) | __SUN3_PAGE_NOCACHE))			\
+	 : ((MMU_IS_851 || MMU_IS_030)						\
+	    ? (__pgprot(pgprot_val(prot) | _PAGE_NOCACHE030))			\
+	    : (MMU_IS_040 || MMU_IS_060)					\
+	    ? (__pgprot((pgprot_val(prot) & _CACHEMASK040) | _PAGE_NOCACHE_S))	\
+	    : (prot)))
+
 #endif /* !__ASSEMBLY__ */
 
 /*
diff -Nru a/include/asm-ppc/pgtable.h b/include/asm-ppc/pgtable.h
--- a/include/asm-ppc/pgtable.h	Wed Oct  8 09:05:37 2003
+++ b/include/asm-ppc/pgtable.h	Wed Oct  8 09:05:37 2003
@@ -521,6 +521,11 @@
 	pte_update(ptep, 0, _PAGE_DIRTY);
 }
 
+/*
+ * Macro to mark a page protection value as "uncacheable".
+ */
+#define pgprot_noncached(prot)	(__pgprot(pgprot_val(prot) | _PAGE_NO_CACHE | _PAGE_GUARDED))
+
 #define pte_same(A,B)	(((pte_val(A) ^ pte_val(B)) & ~_PAGE_HASHPTE) == 0)
 
 #define pmd_page(pmd)	(pmd_val(pmd))
diff -Nru a/include/asm-ppc64/pgtable.h b/include/asm-ppc64/pgtable.h
--- a/include/asm-ppc64/pgtable.h	Wed Oct  8 09:05:37 2003
+++ b/include/asm-ppc64/pgtable.h	Wed Oct  8 09:05:37 2003
@@ -317,6 +317,11 @@
 	pte_update(ptep, 0, _PAGE_DIRTY);
 }
 
+/*
+ * Macro to mark a page protection value as "uncacheable".
+ */
+#define pgprot_noncached(prot)	(__pgprot(pgprot_val(prot) | _PAGE_NO_CACHE | _PAGE_GUARDED))
+
 #define pte_same(A,B)	(((pte_val(A) ^ pte_val(B)) & ~_PAGE_HPTEFLAGS) == 0)
 
 /*
diff -Nru a/include/asm-x86_64/pgtable.h b/include/asm-x86_64/pgtable.h
--- a/include/asm-x86_64/pgtable.h	Wed Oct  8 09:05:37 2003
+++ b/include/asm-x86_64/pgtable.h	Wed Oct  8 09:05:37 2003
@@ -342,6 +342,11 @@
 static inline void ptep_mkdirty(pte_t *ptep)			{ set_bit(_PAGE_BIT_DIRTY, ptep); }
 
 /*
+ * Macro to mark a page protection value as "uncacheable".
+ */
+#define pgprot_noncached(prot)	(__pgprot(pgprot_val(prot) | _PAGE_PCD | _PAGE_PWT))
+
+/*
  * Conversion functions: convert a page and protection to a page entry,
  * and a page entry and page directory to the page they refer to.
  */